﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CTP.Entitys
{
    /// <summary>
    /// 方法返回结果
    /// </summary>
    public struct ReturnInfo
    {
        /// <summary>
        /// 获取或设置是否成功
        /// </summary>
        public bool IsSuccess;

        /// <summary>
        /// 获取或设置错误码
        /// </summary>
        public int ErrorCode;

        /// <summary>
        /// 获取或设置错误信息
        /// </summary>
        public string ErrorMessage;

        /// <summary>
        /// 以指定参数创建实例
        /// </summary>
        /// <param name="isSucess"></param>
        /// <param name="errorCode"></param>
        /// <returns></returns>
        public static ReturnInfo Create(bool isSucess, int errorCode)
        {
            return new ReturnInfo()
            {
                IsSuccess = isSucess,
                ErrorCode = errorCode,
                ErrorMessage = errorCode == 0 ? "" : Exceptions.ErrorCode.GetErrorMessage(errorCode)
            };
        }

        /// <summary>
        /// 以指定参数创建实例
        /// </summary>
        /// <param name="isSucess"></param>
        /// <param name="errorCode"></param>
        /// <returns></returns>
        public static ReturnInfo Create(bool isSucess, int errorCode, string errorMessage)
        {
            return new ReturnInfo()
            {
                IsSuccess = isSucess,
                ErrorCode = errorCode,
                ErrorMessage = errorMessage
            };
        }
    }
}
